package com.eshop.eshop2021_v1.controller.before;

import com.eshop.eshop2021_v1.pojo.Address;
import com.eshop.eshop2021_v1.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: 若若叶
 * @date: 2021/10/9 9:25 FileName: AddressController Description:
 */
@Controller
@RequestMapping("/address")
public class AddressController {
  @Autowired private AddressService addressService;

  @RequestMapping("/toAddressPage")
  public String toAddressPage(HttpSession session, Model model) {
    List<Address> allAddress = addressService.getAllAddressById(session);
    model.addAttribute("allAddress", allAddress);
    return "user/userAddress";
  }

  @PostMapping("/doAddAddress")
  public String doAddAddress(String addressDetail, HttpSession session) {
    return addressService.addAddress(addressDetail, session);
  }
  // 设置默认
  @RequestMapping("/setDefault")
  public String setDefauil(Integer aid, HttpSession session) {
    return addressService.setDefauilAddress(aid, session);
  }
  // 删除一条地址
  @RequestMapping("/deleteAddress")
  public String deleteAddress(Integer aid) {
    return addressService.deleteAddress(aid);
  }
}
